<template>
  <div>
    <el-select placeholder="请选择" v-model="brandIdTmp" filterable clearable>
      <el-option
        v-for="item in brands"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      ></el-option>
    </el-select>
  </div>
</template>

<script>

import { categoryBrandRelationList } from '@/api/product/brand'

export default {
  components: {},
  props: {
    categoryId: String,
    brandId: String
  },
  data() {
    return {
      brands: [],
      brandIdTmp: this.brandId
    };
  },
  computed: {},
  watch: {
    brandIdTmp(val) {
      this.$emit('update:brandId',val)
    },
    categoryId(val) {
      this.loadData()
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      if (!this.categoryId) {
        this.brands = []
        this.brandIdTmp = ''
        return
      }
      categoryBrandRelationList(this.categoryId).then(res => {
        if (res.success) {
          this.brands = res.data;
        }
      })
    }
  },
};
</script>
